/**
 * 
 */
package ie.tippinst.mjp;

/**
 * @author Mike
 *
 */
public class Puzzle {
	int width, bWidth, height, bHeight;	//dimensions of grid and block
	int max;							//max possible value of cell
	Cell[][] Grid; 						// = new Cell[9][9];	//the sudoku grid
	int unsolved;						//unsolved cells 0 when puzzle solved
	
	public void Create(int w, int h, int[] clues){
		width = w;
		height = h;
		int count = 0;
		
		Grid = new Cell[width][height]; // set size of puzzle
		//calculate the max possible value for a cell 
		bWidth = (int) Math.sqrt(width);
		bHeight = (int) Math.sqrt(height);
		max = bWidth * bHeight;
		for(int c = 0; c < width; c++){
			for(int r = 0; r < height; r++){
				if(clues[count] == 0){
					Grid[c][r] = new Cell(clues[count], false, max);
					Grid[c][r].addAllPos(max);
					unsolved++;
				}
				else{
					Grid[c][r] = new Cell(clues[count], true, max);
				}
				count++;
			}
		}
	}
// eugene recommends implementing some way of checking mini-grids

	// Check that the puzzle's dimension are valid i.e. it can be divided into equal blocks
	private boolean checkValidDim(int width2, int height2) {
		int wCheck = (int) Math.sqrt(width2);
		int hCheck = (int) Math.sqrt(height2);
		
		if((wCheck * wCheck) != width2)
			return false;
		if((hCheck * hCheck) != height2)
			return false;
		
		return true;
		
		
	}
}
